#include "Borrower_t.h"
#include "Person.h"
#include "Book_t.h"
using namespace std;
Borrower_t::Borrower_t(Person *p, unsigned long id):
person(p), borrower_id(id) {}

Borrower_t::~Borrower_t(){}

string Borrower_t::getName() const {
	return this->person->getName();
}

unsigned long Borrower_t::getID() const {
	return this->borrower_id;
}

void Borrower_t::writeBorrowed(const Book_t* book){
	this->borrowedBooks.push_back(book);
}

void Borrower_t::removeBorrowed(const Book_t* book){
	this->borrowedBooks.remove(book);
}

bool Borrower_t::hasBooks() const{
	return !borrowedBooks.empty();
}

ostream& operator<<(ostream& os, const Borrower_t& borrower){
	os << borrower.getName() << " " << borrower.getID() << endl;
	os << "Books Taken: ";
	if(borrower.borrowedBooks.size() > 0){
		os << endl;
		list<const Book_t*>::const_iterator it;
		int count = 1;
		for(it=borrower.borrowedBooks.begin();it!=borrower.borrowedBooks.end();++it){
			os << "\t" << count << ": " << (**it).getISBN() << " " << (**it).getTitle() << endl;
			++count;
		}
	}else{
		os << "[empty]" << endl;
	}
	return os;
}